package lookie.swing.tree.model;

import java.util.Enumeration;
import java.util.Vector;

import javax.swing.tree.TreeNode;

public abstract class LazyTreeNode implements TreeNode {

	private TreeNode parent;

	private Vector<TreeNode> children;

	protected LazyTreeNode() {
		super();
	}

	protected LazyTreeNode(TreeNode parent) {
		super();
		this.parent = parent;
	}

	public Enumeration<TreeNode> children() {
		return children.elements();
	}

	public TreeNode getChildAt(int childIndex) {
		return children.get(childIndex);
	}

	public int getChildCount() {
		return children.size();
	}

	public int getIndex(TreeNode node) {
		return children.indexOf(node);
	}

	public TreeNode getParent() {
		return parent;
	}
	
	public boolean getAllowsChildren() {
		return !isLeaf();
	}

	public boolean isLeaf() {
		return false;
	}

	public boolean isLoaded() {
		return children != null;
	}

	public void fill(TreeNode[] nodes) {
		children = new Vector<TreeNode>();
		for (TreeNode node : nodes) {
			children.add(node);
		}
	}

	public void clear() {
		children = null;
	}

}
